package br.ufrn.cep.eEtica.integracao.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@Entity
public class ItemPauta {
	
	
	@Id
	@GeneratedValue
	private int id;
	
	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinColumn(name="reuniao_fk")
	private Reuniao reuniao;
	
	private String descricao;
	
	@OneToMany(mappedBy="itemPauta")
	private List<SubItemPauta> subitens;
	
	public ItemPauta() {
		// TODO Auto-generated constructor stub
	}

	@XmlElement
	public Reuniao getReuniao() {
		return reuniao;
	}

	public void setReuniao(Reuniao reuniao) {
		this.reuniao = reuniao;
	}

	@XmlElement
	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	@XmlElement
	public List<SubItemPauta> getSubitens() {
		return subitens;
	}

	public void setSubitens(List<SubItemPauta> subitens) {
		this.subitens = subitens;
	}

	@XmlAttribute
	public int getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((descricao == null) ? 0 : descricao.hashCode());
		result = prime * result + id;
		result = prime * result + ((reuniao == null) ? 0 : reuniao.hashCode());
		result = prime * result
				+ ((subitens == null) ? 0 : subitens.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemPauta other = (ItemPauta) obj;
		if (descricao == null) {
			if (other.descricao != null)
				return false;
		} else if (!descricao.equals(other.descricao))
			return false;
		if (id != other.id)
			return false;
		if (reuniao == null) {
			if (other.reuniao != null)
				return false;
		} else if (!reuniao.equals(other.reuniao))
			return false;
		if (subitens == null) {
			if (other.subitens != null)
				return false;
		} else if (!subitens.equals(other.subitens))
			return false;
		return true;
	}
	
	

}
